package com.deco.back.controller.fix;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.deco.domain.vo.fix.FixGeneralDspVo;
import com.deco.domain.vo.fix.FixGeneralVo;
import com.deco.domain.vo.fix.FixTypeVo;
import com.deco.service.fix.FixGeneralService;
import com.deco.service.fix.FixTypeService;
import com.free.common.vo.PageResponseVo;
import com.free.common.vo.PageSearchVo;
import com.free.common.vo.ResultModel;
import com.free.ext.web.spring.annoation.PageSearch;

/**
 * 广告管理 Controller
 * @author lengy
 *
 */
@Controller
public class FixGeneralController {
    @Autowired
    private FixGeneralService fixGeneralService;
    
    @Autowired
    private FixTypeService fixTypeService;

    @RequestMapping(value = "/fix_general_list")
    public ModelAndView fixTypeList(){
        ModelAndView mv = new ModelAndView("fix/fixgenerallist");
        List<FixTypeVo> fixTypeList = fixTypeService.getAllList();
        mv.addObject("typeList", fixTypeList);
        return mv;
    }

    @RequestMapping(value= "/fix_general_list_page.do")
    @ResponseBody
    public PageResponseVo<FixGeneralDspVo> getList(@PageSearch PageSearchVo<FixGeneralDspVo> condition){
        return fixGeneralService.pageInfo(condition);
    }

    @RequestMapping(value = "/fix_general_edit.do")
    public ModelAndView editFixType(Integer id){
        FixGeneralVo vo = null;
        ModelAndView mv = new ModelAndView("fix/fixgeneraledit");
        if(id != null){
            vo = fixGeneralService.getFixGeneral(id);
            mv.addObject("actNm","更新");
        }else{
            vo = new FixGeneralVo();
            vo.setId(0);
            mv.addObject("actNm","新增");
        }
        mv.addObject("obj",vo);
        List<FixTypeVo> fixTypeList = fixTypeService.getAllList();
        mv.addObject("typeList", fixTypeList);
        return mv;
    }

    @RequestMapping(value ="/fix_general_del.do")
    @ResponseBody
    public ResultModel batchDelete(@RequestParam(value = "ids[]")Integer[] ids){
        return fixGeneralService.batchDelete(ids);
    }

    @RequestMapping(value ="/fix_general_edit_submit.do")
    @ResponseBody
    public ResultModel udpate(FixGeneralVo vo){
        return fixGeneralService.save(vo);
    }

    @RequestMapping(value ="/fix_general_status.do")
    @ResponseBody
    public ResultModel updateStatus(FixGeneralVo vo){
        return fixGeneralService.save(vo);
    }


    /**
     *  更新或创建品牌故事
     * @param req
     * @param activeReportVo
     * @return
     */
    @RequestMapping(value="/save")
    @ResponseBody
    public ResultModel save(HttpServletRequest req ,FixGeneralVo fixGeneralVo) {
    	return fixGeneralService.save(fixGeneralVo);
    }


    /**
     *  删除品牌故事
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/del", method = RequestMethod.POST)
    public ResultModel del(HttpServletRequest request) {
    	int id = Integer.parseInt(request.getParameter("id"));

    	return fixGeneralService.delete(id);
    }
}
